package com.batata.continuing.config;

import com.alibaba.fastjson.JSONObject;
import com.batata.continuing.pojo.base.ResultData;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常捕获
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResultData<?> handleException(Exception e) {
        String msg = e.getMessage();
        if (msg == null || msg.isEmpty()) {
            msg = "服务器出错";
        }
        e.printStackTrace();
        return ResultData.error(msg);
    }
}
